import turtle

# 步长
step = 100
width = step * 2 * 6
height = width * 2 / 3 / 2

# 设置画布
screen = turtle.getscreen()
screen.title("数线（number line）或数轴（number axis）")
screen.setup(width + 100, height + 100)

pen = turtle.getpen()
pen.shape("turtle")
pen.speed(0) # 速度放到最快

# 画x轴
pen.teleport(0 - width / 2, 0)
pen.setheading(0)
pen.forward(width)
# 画箭头
pen.left(150)
pen.forward(10)
pen.backward(10)
pen.right(300)
pen.forward(10)

# 画x标尺
def draw_x_scale(x):
    pen.teleport(x * step, -5)
    pen.setheading(0)
    pen.left(90)
    pen.forward(10)
    pen.teleport(x * step, -48)
    pen.write(x, align="center", font=("Arial", 32, "normal"))

# 画x轴正数标尺
for i in range(int(width / 2 / step)):
    draw_x_scale(i)
# 画x轴负数标尺
for i in range(1, int(width / 2 / step)):
    draw_x_scale(-i)

# 画点
def draw_point(x):
    # 设置颜色
    if x > 0:
        pen.pencolor("blue")
    elif x == 0:
        pen.pencolor("purple")
    else:
        pen.pencolor("red")
    # 画点
    pen.teleport(x * step, 0)
    pen.dot(7)
    pen.setheading(90)
    for i in range(7):
        if i % 2 == 0:
            pen.down()
        else:
            pen.up()
        pen.forward(5)
    pen.write(x, align="center", font=("Arial", 32, "normal"))
    # 回到原点
    pen.teleport(0, 0)
    pen.setheading(0)

# 画点
draw_point(3.14)
draw_point(1.618)
draw_point(0)
draw_point(-1.414)
draw_point(-2.718)

# 收笔
pen.hideturtle()
# 持续显示
screen.mainloop()